package com.elinkway.infinitemovies.ui.activity.commonwebview;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.DownloadListener;

import com.apkfuns.logutils.LogUtils;
import com.elinkway.infinitemovies.adaction.CommonAdActionHandle;
import com.elinkway.infinitemovies.bean.ServerPayload;

public class CommonWebViewManager {

    private String TAG = "CommonWebViewManager";

    private CommonWebViewActivity mCommonActivity;
    private String mFromPage;
    private String mAppName;
    private String mPackageName;
    private String mAdPos;

    public CommonWebViewManager(Context context) {
        mCommonActivity = (CommonWebViewActivity) context;
    }

    private DownloadListener mDownLoadListener = new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetpe, long contentLength) {
            LogUtils.e("Download url:" + url);
            try {
                CommonAdActionHandle.getInstance().downloadApp(CommonWebViewManager.this.mCommonActivity, url, mAdPos, mAppName, mPackageName, true);
            } catch (Exception e) {
                //Inner app download error call browser
                try {
                    //调用系统浏览器进行下载
                    Uri uri = Uri.parse(url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    mCommonActivity.startActivity(intent);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    };

    public DownloadListener getmDownLoadListener() {
        return mDownLoadListener;
    }

    public void setFromPage(String fromPage) {
        mFromPage = fromPage;
    }

    public String getAppName() {
        return mAppName;
    }

    public void setAppName(String mAppName) {
        this.mAppName = mAppName;
    }

    public String getPackageName() {
        return mPackageName;
    }

    public void setPackageName(String mPackageName) {
        this.mPackageName = mPackageName;
    }

    public String getAdPos() {
        return mAdPos;
    }

    public void setAdPos(String mAdPos) {
        this.mAdPos = mAdPos;
    }
}
